package com.cakebackoffice.clientsoap;

import com.cakebackoffice.clientsoap.Exception.SoapClientException;
import com.cakebackoffice.clientsoap.Exception.SoapComException;
import com.cakebackoffice.clientsoap.contract.*;

import java.util.*;

public class CakeBackOfficeSoapClient extends SoapClient {
    private static final String NAMESPACE = "http://cakeathome.org/backoffice/";
    private static final String URI = "http://vincentcotro.fr/backoffice/ServiceBackOffice.asmx";
    private static final Boolean DOTNET = true;

    private StringMethod helloWorld = new StringMethod(this, "HelloWorld", null);
    private StringMethod toString = new StringMethod(this, "ToString", null);
    private StringMethod createClient = new StringMethod(this, "createClient", null);
    private ObjectMethod<Catalog> getAbsoluteCatalog = new ObjectMethod<Catalog>(this, "getAbsoluteCatalog", null, Catalog.class);
    private StringMethod insertProductType = new StringMethod(this, "insertProductType", null);
    private StringMethod updateProductType = new StringMethod(this, "updateProductType", null);
    private StringMethod deleteProductType = new StringMethod(this, "deleteProductType", null);
    private StringMethod setLocalPriceProductType = new StringMethod(this, "setLocalPriceProductType", null);
    private StringMethod setRecommendedPriceProductType = new StringMethod(this, "setRecommendedPriceProductType", null);
    private StringMethod insertMenuType = new StringMethod(this, "insertMenuType", null);
    private StringMethod updateMenuType = new StringMethod(this, "updateMenuType", null);
    private StringMethod deleteMenuType = new StringMethod(this, "deleteMenuType", null);
    private StringMethod setLocalPriceMenuType = new StringMethod(this, "setLocalPriceMenuType", null);
    private StringMethod setRecommendedPriceMenuType = new StringMethod(this, "setRecommendedPriceMenuType", null);
    private StringMethod insertProductCategory = new StringMethod(this, "insertProductCategory", null);
    private StringMethod updateProductCategory = new StringMethod(this, "updateProductCategory", null);
    private StringMethod deleteProductCategory = new StringMethod(this, "deleteProductCategory", null);
    private StringMethod addProductTypeToCategory = new StringMethod(this, "addProductTypeToCategory", null);
    private StringMethod removeProductTypeToCategory = new StringMethod(this, "removeProductTypeToCategory", null);
    private StringMethod addProductCategoryToCategory = new StringMethod(this, "addProductCategoryToCategory", null);
    private StringMethod removeProductCategoryToCategory = new StringMethod(this, "removeProductCategoryToCategory", null);
    private ArrayMethod<Store> getStores = new ArrayMethod<Store>(this, "getStores", null, Store.class);
    private StringMethod insertStore = new StringMethod(this, "insertStore", null);
    private StringMethod updateStore = new StringMethod(this, "updateStore", null);
    private StringMethod deleteStore = new StringMethod(this, "deleteStore", null);
    private StringMethod addDeliveryMan = new StringMethod(this, "addDeliveryMan", null);
    private StringMethod removeDeliveryMan = new StringMethod(this, "removeDeliveryMan", null);
    private ArrayMethod<DeliveryMan> getDeliveryMen = new ArrayMethod<DeliveryMan>(this, "getDeliveryMen", null, DeliveryMan.class);
    private ArrayMethod<DeliveryMan> getLocalDeliveryMen = new ArrayMethod<DeliveryMan>(this, "getDeliveryMen", null, DeliveryMan.class);
    private ObjectMethod getDeliveryMan = new ObjectMethod<DeliveryMan>(this, "getDeliveryMan", null, DeliveryMan.class);
    private ArrayMethod<Order> getFollowingOrderList = new ArrayMethod<Order>(this, "getFollowingOrderList", null, Order.class);
    private ArrayMethod<Order> getOrderList = new ArrayMethod<Order>(this, "getOrderList", null, Order.class);
    private StringMethod insertOrder = new StringMethod(this, "insertOrder", null);
    private StringMethod updateOrder = new StringMethod(this, "updateOrder", null);
    private StringMethod deleteOrder = new StringMethod(this, "deleteOrder", null);
    private StringMethod insertProduct = new StringMethod(this, "getIdProduct", null);
    private StringMethod updateProduct = new StringMethod(this, "updateProduct", null);
    private StringMethod deleteProduct = new StringMethod(this, "deleteProduct", null);
    private StringMethod addProductToOrder = new StringMethod(this, "addProductToOrder", null);
    private StringMethod removeProductFromOrder = new StringMethod(this, "removeProductFromOrder", null);
    private StringMethod addProductTypeToOrder = new StringMethod(this, "addProductTypeToOrder", null);
    private StringMethod removeProductTypeFromOrder = new StringMethod(this, "removeProductTypeFromOrder", null);
    private StringMethod addLivreurToOrder = new StringMethod(this, "addLivreurToOrder", null);
    private StringMethod removeLivreurFromOrder = new StringMethod(this, "removeLivreurFromOrder", null);
    private StringMethod addVehicleToOrder = new StringMethod(this, "addVehicleToOrder", null);
    private StringMethod removeVehicleFromOrder = new StringMethod(this, "removeVehicleFromOrder", null);

    public Method[] methodArray = new Method[]{
            helloWorld,
            toString,
            createClient,
            getAbsoluteCatalog,
            insertProductType,
            updateProductType,
            deleteProductType,
            setLocalPriceProductType,
            setRecommendedPriceProductType,
            insertMenuType,
            updateMenuType,
            deleteMenuType,
            setLocalPriceMenuType,
            setRecommendedPriceMenuType,
            insertProductCategory,
            updateProductCategory,
            deleteProductCategory,
            addProductCategoryToCategory,
            removeProductCategoryToCategory,
            addProductTypeToCategory,
            removeProductTypeToCategory,
            getStores,
            insertStore,
            updateStore,
            deleteStore,
            addDeliveryMan,
            removeDeliveryMan,
            getDeliveryMen,
            getLocalDeliveryMen,
            getDeliveryMan,
            getFollowingOrderList,
            getOrderList,
            insertOrder,
            updateOrder,
            deleteOrder,
            insertProduct,
            updateProduct,
            deleteProduct,
            addProductToOrder,
            removeProductFromOrder,
            addProductTypeToOrder,
            removeProductTypeFromOrder,
            addLivreurToOrder,
            removeLivreurFromOrder,
            addVehicleToOrder,
            removeVehicleFromOrder
    };

    public List<Method> methodsList = new ArrayList<Method>(Arrays.asList(methodArray));

    private static Call makeMethod(String methodName) {
        return new Call(NAMESPACE + methodName, methodName, NAMESPACE, URI, DOTNET);
    }

    @Override
    public String getNameSpace() {
        return NAMESPACE;
    }

    @Override
    public String getURI() {
        return URI;
    }

    @Override
    public boolean isDotNet() {
        return DOTNET;

    }

    public String HelloWorld() throws SoapComException, SoapClientException {
        return helloWorld.getResult();
    }

    public String toString(Object objet) throws SoapComException, SoapClientException {
        toString.setParameter("objet", objet);
        return toString.getResult();
    }

    public String createClient(SimpleClient simpleClient) throws SoapComException, SoapClientException {
        createClient.setParameter("client", simpleClient);
        return createClient.getResult();
    }

    public Catalog getAbsoluteCatalog() throws SoapComException, SoapClientException {
        return getAbsoluteCatalog.getResult();
    }

    public Integer insertProductType(ProductType productType) throws SoapComException, SoapClientException {
        insertProductType.setParameter("productType", productType);
        return Integer.parseInt(insertProductType.getResult());
    }


    public Boolean updateProductType(ProductType productType) throws SoapComException, SoapClientException {
        updateProductType.setParameter("productType", productType);
        return Boolean.parseBoolean(updateProductType.getResult());
    }

    public Boolean deleteProductType(Integer idProductType) throws SoapComException, SoapClientException {
        deleteProductType.setParameter("idProductType", idProductType);
        return Boolean.parseBoolean(deleteProductType.getResult());
    }

    public Boolean setLocalPriceProductType(Integer idProductType, Integer idStore, Float value) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("idStore", idStore);
        parameters.put("value", value);
        setLocalPriceProductType.setParameters(parameters);
        return Boolean.parseBoolean(setLocalPriceProductType.getResult());
    }

    public Boolean setRecommendedPriceProductType(Integer idProductType, Float value) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("value", value);
        setRecommendedPriceProductType.setParameters(parameters);
        return Boolean.parseBoolean(setRecommendedPriceProductType.getResult());
    }

    public Integer insertMenuType(MenuType menuType) throws SoapComException, SoapClientException {
        insertMenuType.setParameter("menuType", menuType);
        return Integer.parseInt(insertMenuType.getResult());
    }

    public Boolean updateMenuType(MenuType menuType) throws SoapComException, SoapClientException {
        updateMenuType.setParameter("menuType", menuType);
        return Boolean.parseBoolean(updateMenuType.getResult());
    }

    public Boolean deleteMenuType(Integer idMenu) throws SoapComException, SoapClientException {
        deleteMenuType.setParameter("idMenu", idMenu);
        return Boolean.parseBoolean(deleteMenuType.getResult());
    }

    public Boolean setLocalPriceMenuType(Integer idMenuType, Integer idStore, Integer value) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idMenuType", idMenuType);
        parameters.put("idStore", idStore);
        parameters.put("value", value);
        setLocalPriceMenuType.setParameters(parameters);
        return Boolean.parseBoolean(setLocalPriceMenuType.getResult());
    }

    public Boolean setRecommendedPriceMenuType(Integer idMenuType, Float value) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idMenuType", idMenuType);
        parameters.put("value", value);
        setRecommendedPriceMenuType.setParameters(parameters);
        return Boolean.parseBoolean(setRecommendedPriceMenuType.getResult());
    }

    public Integer insertProductCategory(ProductCategory productCategory) throws SoapComException, SoapClientException {
        insertProductCategory.setParameter("productCategory", productCategory);
        return Integer.parseInt(insertProductCategory.getResult());
    }

    public Boolean updateProductCategory(ProductCategory productCategory) throws SoapComException, SoapClientException {
        updateProductCategory.setParameter("productCategory", productCategory);
        return Boolean.parseBoolean(updateProductCategory.getResult());
    }

    public Boolean deleteProductCategory(Integer idCategory) throws SoapComException, SoapClientException {
        deleteProductCategory.setParameter("idCategory", idCategory);
        return Boolean.parseBoolean(deleteProductCategory.getResult());
    }

    public Boolean addProductTypeToCategory(Integer idProductType, Integer idProductCategory) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("idProductCategory", idProductCategory);
        addProductTypeToCategory.setParameters(parameters);
        return Boolean.parseBoolean(addProductTypeToCategory.getResult());
    }

    public Boolean removeProductTypeToCategory(Integer idProductType, Integer idProductCategory) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("idProductCategory", idProductCategory);
        removeProductTypeToCategory.setParameters(parameters);
        return Boolean.parseBoolean(removeProductTypeToCategory.getResult());
    }

    public Boolean addProductCategoryToCategory(Integer idParentCategory, Integer idChildCategory) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idParentCategory", idParentCategory);
        parameters.put("idChildCategory", idChildCategory);
        addProductCategoryToCategory.setParameters(parameters);
        return Boolean.parseBoolean(addProductCategoryToCategory.getResult());
    }

    public Boolean removeProductCategoryToCategory(Integer idParentCategory, Integer idChildCategory) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idParentCategory", idParentCategory);
        parameters.put("idChildCategory", idChildCategory);
        removeProductCategoryToCategory.setParameters(parameters);
        return Boolean.parseBoolean(removeProductCategoryToCategory.getResult());
    }


    public List<Store> getStores() throws SoapComException, SoapClientException {
        return getStores.getResult();
    }

    public Integer insertStore(SimpleStore store) throws SoapComException, SoapClientException {
        insertStore.setParameter("store", store);
        return Integer.parseInt(insertStore.getResult());
    }

    public Boolean updateStore(SimpleStore store) throws SoapComException, SoapClientException {
        updateStore.setParameter("store", store);
        return Boolean.parseBoolean(updateStore.getResult());
    }

    public Boolean deleteStore(Integer idStore) throws SoapComException, SoapClientException {
        deleteStore.setParameter("idStore", idStore);
        return Boolean.parseBoolean(deleteStore.getResult());
    }

    public Boolean addDeliveryMan(Integer idStore, DeliveryMan deliveryMan) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idStore", idStore);
        parameters.put("deliveryMan", deliveryMan);
        addDeliveryMan.setParameters(parameters);
        return Boolean.parseBoolean(addDeliveryMan.getResult());
    }

    public Boolean removeDeliveryMan(int idStore, DeliveryMan deliveryMan) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idStore", idStore);
        parameters.put("deliveryMan", deliveryMan);
        removeDeliveryMan.setParameters(parameters);
        return Boolean.parseBoolean(removeDeliveryMan.getResult());
    }

    public List<DeliveryMan> getDeliveryMen() throws SoapComException, SoapClientException {
        return getDeliveryMen.getResult();
    }

    public List<DeliveryMan> getLocalDeliveryMen(int idStore) throws SoapComException, SoapClientException {
        getLocalDeliveryMen.setParameter("idStore", idStore);
        return getLocalDeliveryMen.getResult();
    }

    public DeliveryMan getDeliveryMan(int idDeliveryMan) throws SoapComException, SoapClientException {
        getDeliveryMan.setParameter("idDeliveryMan", idDeliveryMan);
        return (DeliveryMan) getDeliveryMan.getResult(DeliveryMan.class);
    }

    public List<Order> getFollowingOrderList(int idStore) throws SoapComException, SoapClientException {
        getFollowingOrderList.setParameter("idStore", idStore);
        return getFollowingOrderList.getResult();
    }

    public List<Order> getOrderList(int idStore) throws SoapComException, SoapClientException {
        getOrderList.setParameter("idStore", idStore);
        return getOrderList.getResult();
    }

    public int insertOrder(SimpleOrder order) throws SoapComException, SoapClientException {
        insertOrder.setParameter("order", order);
        return Integer.parseInt(insertOrder.getResult());
    }

    public boolean updateOrder(SimpleOrder order) throws SoapComException, SoapClientException {
        updateOrder.setParameter("order", order);
        return Boolean.parseBoolean(updateOrder.getResult());
    }

    public boolean deleteOrder(int idOrder) throws SoapComException, SoapClientException {
        deleteOrder.setParameter("idOrder", idOrder);
        return Boolean.parseBoolean(deleteOrder.getResult());
    }

    public Integer insertProduct(Product product) throws SoapComException, SoapClientException {
        insertProduct.setParameter("product", product);
        return Integer.parseInt(insertProduct.getResult());
    }

    public boolean updateProduct(Product product) throws SoapComException, SoapClientException {
        updateProduct.setParameter("product", product);
        return Boolean.parseBoolean(updateProduct.getResult());
    }

    public boolean deleteProduct(Product product) throws SoapComException, SoapClientException {
        deleteProduct.setParameter("product", product);
        return Boolean.parseBoolean(deleteProduct.getResult());
    }

    public boolean addProductToOrder(int idProduct, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProduct", idProduct);
        parameters.put("idOrder", idOrder);
        addProductToOrder.setParameters(parameters);
        return Boolean.parseBoolean(addProductToOrder.getResult());
    }

    public boolean removeProductFromOrder(int idProduct, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProduct", idProduct);
        parameters.put("idOrder", idOrder);
        removeProductFromOrder.setParameters(parameters);
        return Boolean.parseBoolean(removeProductFromOrder.getResult());
    }


    public boolean addProductTypeToOrder(int idProductType, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("idOrder", idOrder);
        addProductTypeToOrder.setParameters(parameters);
        return Boolean.parseBoolean(addProductTypeToOrder.getResult());
    }

    public boolean removeProductTypeFromOrder(int idProductType, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idProductType", idProductType);
        parameters.put("idOrder", idOrder);
        removeProductTypeFromOrder.setParameters(parameters);
        return Boolean.parseBoolean(removeProductTypeFromOrder.getResult());
    }

    public boolean addLivreurToOrder(int idLivreur, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idLivreur", idLivreur);
        parameters.put("idOrder", idOrder);
        addLivreurToOrder.setParameters(parameters);
        return Boolean.parseBoolean(addLivreurToOrder.getResult());
    }

    public boolean removeLivreurFromOrder(int idLivreur, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idLivreur", idLivreur);
        parameters.put("idOrder", idOrder);
        removeLivreurFromOrder.setParameters(parameters);
        return Boolean.parseBoolean(removeLivreurFromOrder.getResult());
    }

    public boolean addVehicleToOrder(int idVehicle, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idVehicle", idVehicle);
        parameters.put("idOrder", idOrder);
        addVehicleToOrder.setParameters(parameters);
        return Boolean.parseBoolean(addVehicleToOrder.getResult());
    }

    public boolean removeVehicleFromOrder(int idVehicle, int idOrder) throws SoapComException, SoapClientException {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("idVehicle", idVehicle);
        parameters.put("idOrder", idOrder);
        removeVehicleFromOrder.setParameters(parameters);
        return Boolean.parseBoolean(removeVehicleFromOrder.getResult());
    }

    @Override
    public String toString() {
        return new String("SOAP WebService - Namespace : " + NAMESPACE + " - URI : " + URI + " - DOTNET : " + DOTNET.toString());
    }
}
